
#pragma once

enum FontMark {
	FM_UnMark,
	FM_Rank0, FM_Rank1, FM_Rank2,
	FM_PlanBold0, FM_PlanBold1, FM_PlanBold2, FM_PlanBold3, FM_PlanNormal0, FM_PlanNormal1, FM_PlanNormal2, FM_PlanNormal3,
	FM_TimeNum, FM_TimeMs,
	FM_TileWindowNum
};

typedef struct {
	FontMark mark;
	HFONT hFont;
} stFontMark;

class CFontFactory
{
public:
	CFontFactory();
	~CFontFactory();
	CFontFactory* Create(LPCWSTR fontName, intptr_t nHeight, intptr_t nWidth, intptr_t fnWeight);
	CFontFactory* CreateUnDPI(LPCWSTR fontName, intptr_t nHeight, intptr_t nWidth, intptr_t fnWeight);
	CFontFactory* Create(intptr_t nPointSize, LPCWSTR lpszFaceName);
	CFontFactory* Create(const CWnd&wnd, bool bold);
	CFontFactory* Add(HFONT hFont);
	CFontFactory* AttachCtrl(CWnd &wnd, bool delOldFont = false);
	CFontFactory* SetMark(FontMark mark);
	__forceinline CFontFactory* Create(const CWnd *pWnd, bool bold)
	{
		if (pWnd) Create(*pWnd, bold);
		return this;
	}
	__forceinline CFontFactory* CreateAndAttach(CWnd&wnd, bool bold, bool delOldFont = false)
	{
		Create(wnd, bold); return AttachCtrl(wnd, delOldFont);
	}
	__forceinline CFontFactory* CreateAndAttach(CWnd *pWnd, bool bold, bool delOldFont = false)
	{
		if (pWnd) CreateAndAttach(*pWnd, bold, delOldFont);
		return this;
	}
	__forceinline CFontFactory* AttachCtrl(CWnd *pWnd, bool delOldFont = false)
	{
		if (pWnd) AttachCtrl(*pWnd, delOldFont);
		return this;
	}
	__forceinline CFontFactory* AttachCtrl(CWnd &wnd, HFONT hFont, bool delOldFont = false)
	{
		m_lastFont = hFont; return AttachCtrl(wnd, delOldFont);
	}
	__forceinline CFontFactory* AttachCtrl(CWnd *pWnd, HFONT hFont, bool delOldFont = false)
	{
		if (pWnd) AttachCtrl(*pWnd, hFont, delOldFont);
		return this;
	}
	__forceinline CFontFactory* AttachCtrl(CWnd &wnd, FontMark mark, bool delOldFont = false)
	{
		HFONT h = GetMark(mark); if (h) { m_lastFont = h; return AttachCtrl(wnd, delOldFont); }
		return this;
	}
	__forceinline CFontFactory* AttachCtrl(CWnd *pWnd, FontMark mark, bool delOldFont = false)
	{
		if (pWnd) AttachCtrl(*pWnd, mark, delOldFont);
		return this;
	}
	__forceinline HFONT GetLast() const { return m_lastFont; }
	__forceinline HFONT GetMark(FontMark mark) const
	{
		if (m_Mark) for (intptr_t i = 0; i < m_MarkNum; i++) if (m_Mark[i].mark == mark) return m_Mark[i].hFont;
		return nullptr;
	}
protected:
	void RemoveFont(HFONT oldFont);
	intptr_t m_FontNum;
	HFONT *m_Font;
	HFONT m_lastFont;
	intptr_t m_MarkNum;
	stFontMark *m_Mark;
};
